<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<link th:href="@{/assets/plugins/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
<link th:href="@{/assets/plugins/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>

<body class="gray-bg">
<div class="ui-layout-west">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                    <i class="fa icon-grid"></i> 栏目
                </div>
                <div class="box-tools pull-right">
<!--                    <a type="button" class="btn btn-box-tool menuItem" href="#" onclick="dept()" title="管理部门"><i
                            class="fa fa-edit"></i></a>-->
                    <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                            class="fa fa-chevron-up"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                            class="fa fa-chevron-down"></i></button>
                    <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新"><i
                            class="fa fa-refresh"></i></button>
                </div>
            </div>
            <div class="ui-layout-content">
                <div id="tree" class="ztree"></div>
            </div>
        </div>
    </div>
</div>

<div class="container-div ui-layout-center">
    <div class="row">

        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input type="hidden" id="categoryId" name="categoryId">
                <div class="select-list">
                    <ul>
                        <li>
                            标题：<input type="text" name="title"/>
                        </li>

                        <!--      <li>
                                  文章链接：<input type="text" name="link"/>
                              </li>

                              <li>
                                  标题颜色：<input type="text" name="color"/>
                              </li>

                              <li>
                                  文章图片：<input type="text" name="image"/>
                              </li>

                              <li>
                                  关键字：<input type="text" name="keywords"/>
                              </li>

                              <li>
                                  描述、摘要：<input type="text" name="description"/>
                              </li>

                              <li>
                                  权重，越大越靠前：<input type="text" name="weight"/>
                              </li>

                              <li>
                                  权重期限：<input type="text" name="weightDate"/>
                              </li>

                              <li>
                                  点击数：<input type="text" name="hits"/>
                              </li>

                              <li>
                                  推荐位，多选：<input type="text" name="posid"/>
                              </li>

                              <li>
                                  自定义内容视图：<input type="text" name="customContentView"/>
                              </li>

                              <li>
                                  视图配置：<input type="text" name="viewConfig"/>
                              </li>

                              <li>
                                  创建者：<input type="text" name="createBy"/>
                              </li>

                              <li>
                                  创建时间：<input type="text" name="createDate"/>
                              </li>

                              <li>
                                  更新者：<input type="text" name="updateBy"/>
                              </li>

                              <li>
                                  更新时间：<input type="text" name="updateDate"/>
                              </li>

                              <li>
                                  备注信息：<input type="text" name="remarks"/>
                              </li>

                              <li>
                                  删除标记：<input type="text" name="delFlag"/>
                              </li>
      -->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="cms:article:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary btn-edit disabled" onclick="$.operate.editFull()"
               shiro:hasPermission="cms:article:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="cms:article:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="cms:article:export">
                    <i class="fa fa-download"></i> 导出
             </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>

<script th:src="@{/assets/plugins/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/assets/plugins/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "cms/article";
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        queryList();
        queryTree();
    });

    function queryList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "文章",
            search: false,
            showExport: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                /*{
                    field: 'categoryId',
                    title: '栏目编号',
                    sortable: true
                },*/
                {
                    filed: 'category',
                    title: '栏目',
                    sortable: true,
                    formatter: function (value, row, index) {
                        // console.log(value, row, index);
                        if (row) {
                            return row.category.name;
                        }
                        return '';
                    }
                },
                {
                    field: 'title',
                    title: '标题',
                    sortable: true
                },
                // {
                //     field: 'link',
                //     title: '文章链接',
                //     sortable: true
                // },
                // {
                //     field: 'color',
                //     title: '标题颜色',
                //     sortable: true
                // },
                // {
                //     field: 'image',
                //     title: '文章图片',
                //     sortable: true
                // },
                // {
                //     field: 'keywords',
                //     title: '关键字',
                //     sortable: true
                // },
                // {
                //     field: 'description',
                //     title: '描述、摘要',
                //     sortable: true
                // },
                {
                    field: 'weight',
                    title: '权重',
                    sortable: true
                },
                // {
                //     field: 'weightDate',
                //     title: '权重期限',
                //     sortable: true
                // },
                {
                    field: 'hits',
                    title: '点击数',
                    sortable: true
                },
                // {
                //     field: 'posid',
                //     title: '推荐位，多选',
                //     sortable: true
                // },
                // {
                //     field: 'customContentView',
                //     title: '自定义内容视图',
                //     sortable: true
                // },
                // {
                //     field: 'viewConfig',
                //     title: '视图配置',
                //     sortable: true
                // },
                {
                    field: 'user',
                    title: '发布者',
                    sortable: true,
                    formatter: function (value, row, index) {
                        //console.log(row);
                        if (value) {
                            return value.userName;
                        }
                        return '';
                    }
                },
                // {
                //     field: 'createDate',
                //     title: '创建时间',
                //     sortable: true
                // },
                // {
                //     field: 'updateBy',
                //     title: '更新者',
                //     sortable: true
                // },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    sortable: true
                },
                // {
                //     field: 'remarks',
                //     title: '备注信息',
                //     sortable: true
                // },
                // {
                //     field: 'delFlag',
                //     title: '删除标记',
                //     sortable: true
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="#" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    function queryTree() {
        var url = ctx + "cms/category/treeData";
        var options = {
            url: url,
            expandLevel: 2,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            console.log(event, treeId, treeNode, treeNode.id);
            $("#categoryId").val(treeNode.id);
            // $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }
</script>
</body>
</html>